-
Notifications
You must be signed in to change notification settings - Fork 18
Fix loadjson failed because of sql params not match #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| if len(rows) == 1 && rows[0].ColumnCount() <= 1 { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When data is empty, usually only has query_id, insert will fail
| placeholders := strings.Repeat("?,", row.ColumnCount()) | ||
| // Get rid of the trailing comma. | ||
| placeholders = placeholders[:len(placeholders)-1] | ||
| sqlStmt := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", | ||
| table, strings.Join(row.ColumnNames, ","), placeholders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes cmd loadjson with the sample data
$ ./pbench_darwin_arm64 loadjson -n test --mysql ./mysql.conf -o ./test ./cmd/loadjson/20240422_013209_00111_k6ve9_shows_schema.json
{"level":"info","output_path":"test/test","time":"2025-10-29T21:58:11Z","message":"output directory"}
{"level":"info","log_path":"test/test/loadjson.log","time":"2025-10-29T21:58:11Z","message":"log file will be saved to this path"}
{"level":"info","parallelism":16,"time":"2025-10-29T21:58:11Z"}
{"level":"info","path":"./cmd/loadjson/20240422_013209_00111_k6ve9_shows_schema.json","time":"2025-10-29T21:58:11Z","message":"start to process file"}
{"level":"error","error":"sql: expected 37 arguments, got 38","path":"./cmd/loadjson/20240422_013209_00111_k6ve9_shows_schema.json","time":"2025-10-29T21:58:12Z","message":"failed to insert event listener record"}
{"level":"info","file_loaded":0,"time":"2025-10-29T21:58:12Z"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this happen? I don't understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the rows is an array of operator stats, when it extract the rows, the first row has 37 column with 37 values, and some of the other rows has 38 columns with 38 values, but the statement is created by the first row, that makes the values not matching for some of the other rows which have 38 columns
This PR fixes: